#include "thread_list.h"


template <typename T>
ThreadList<T>::ThreadList(void)
{
	size = 0;
	first.value = NULL;
	first.next = NULL;
}


template <typename T>
ThreadList<T>::~ThreadList(void)
{
	if (first.value)
	{
		ThreadListNode *pre, *post = &first;

		while (post->next)
		{
			pre = post;
			post = post->next;
			delete pre->value;
		}

		delete post->value;
	}
}


template <typename T>
void ThreadList<T>::push(T value)
{
	ThreadListNode node;
	node.next = &first;
	node.value = value;
	first = node;
	size++;
}


template <typename T>
T ThreadList<T>::pop(void)
{
	T value = first.value;
	first.value = NULL;

	if (first.next)
		first = *(first.next);

	return value;
}


template <typename T>
unsigned int ThreadList<T>::get_size(void)
{
	return size;
}
